//
//  ViewControllerForGuidePage.m
//  世界
//
//  Created by admin on 16/3/9.
//  Copyright © 2016年 admin. All rights reserved.
//

#import "ViewControllerForGuidePage.h"
#define WIDTH self.view.frame.size.width
#define HEIGHT self.view.frame.size.height
@interface ViewControllerForGuidePage ()<UIScrollViewDelegate>

@property(nonatomic,retain)UIScrollView *scrol;
@property(nonatomic,retain)UIPageControl *page;

@end

@implementation ViewControllerForGuidePage

- (void)dealloc
{
    [_scrol release];
    [_page release];
    [super dealloc];
}


- (void)viewDidLoad
{
    [super viewDidLoad];
    self.scrol = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT)];
    self.scrol.delegate = self;
    self.scrol.showsHorizontalScrollIndicator = NO;
    self.scrol.contentSize = CGSizeMake(WIDTH * 2, 0);
    self.scrol.pagingEnabled = YES;
    self.scrol.bounces = NO;
    self.scrol.tag = 100;
    [self.view addSubview:self.scrol];
    
    [_scrol release];
    
    UIImageView *imageViewFiest = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT)];
    
    imageViewFiest.image = [UIImage imageNamed:@"page1.jpg"];
    
    [self.scrol addSubview:imageViewFiest];
    
    [imageViewFiest release];
    
    UIImageView *imageViewSecond = [[UIImageView alloc]initWithFrame:CGRectMake(WIDTH, 0, WIDTH, HEIGHT)];
    
    imageViewSecond.image = [UIImage imageNamed:@"page0.jpeg"];
    
    imageViewSecond.userInteractionEnabled = YES;
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    
    button.frame = CGRectMake(WIDTH/5, HEIGHT-100, WIDTH/5 *3, 40);
    
    [button setTitle:@"开启美图时代" forState:UIControlStateNormal];
    
    [button addTarget:self action:@selector(clickAction:) forControlEvents:UIControlEventTouchUpInside];
    
    button.backgroundColor = [UIColor clearColor];
    button.layer.borderWidth = 3;
    
    button.layer.borderColor= [[UIColor blueColor]CGColor];
    
    button.layer.cornerRadius = 20;
    
    button.layer.masksToBounds = YES;
    
    
    button.alpha =0.6;
    
    [imageViewSecond addSubview:button];
    
    [self.scrol addSubview:imageViewSecond];
    
    [imageViewSecond release];
    
    self.page = [[UIPageControl alloc]initWithFrame:CGRectMake(WIDTH / 2 - 20, HEIGHT - 30, 40, 20)];
    
    self.page.backgroundColor = [UIColor colorWithRed:0.702 green:0.627 blue:0.557 alpha:1.00];
    
    [self.page addTarget:self action:@selector(pageAction:) forControlEvents:UIControlEventValueChanged];
    
    self.page.numberOfPages = 2;
    
    self.page.backgroundColor = [UIColor clearColor];
    
    self.page.currentPageIndicatorTintColor = [UIColor redColor];
    
    self.page.pageIndicatorTintColor = [UIColor grayColor];

    [self.view addSubview:self.page];
    
    [_page release];
}


-(void)clickAction:(UIButton *)button
{
    [[NSNotificationCenter defaultCenter] postNotificationName:@"GuidePage" object:nil];
}


-(void)pageAction:(UIPageControl *)page
{
    self.scrol.contentOffset = CGPointMake(page.currentPage * WIDTH, 0);
}

-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
    self.page.currentPage =  scrollView.contentOffset.x / WIDTH;
}



- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
}

@end
